/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presentation.view;

import java.awt.Color;
import java.awt.Dimension;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.swing.*;
import presentation.controller.ControlPanelMain;
import presentation.controller.ControlPanelMyAccount;
import presentation.view.custom.TaskRenderer;
import vo.ProjectVO;
import vo.StudentVO;
import vo.TaskVO;

/**
 *
 * @author Joanna 8a
 */
public class MainPanel extends javax.swing.JPanel implements Observer {

    /**
     * Creates new form MainPanel
     */
    TaskRenderer taskRenderer = new TaskRenderer();

    private MainPanel() {
        initComponents();
        jDateChooserInitialTasksDate.setEnabled(false);
        jDateChooserInitialTasksDate.getCalendarButton().setEnabled(true);
        jDateChooserEndTaskDate.setEnabled(false);
        jDateChooserEndTaskDate.getCalendarButton().setEnabled(true);
        jSpinnerPriority.setModel(new javax.swing.SpinnerNumberModel(0, 0, 5, 1));
        jLabelIdTask.setVisible(false);
        update();
    }

    private void loadProjects() {
        StudentVO active = new ControlPanelMyAccount().findByIp();
        int id = active.getCalendarId();
        List<ProjectVO> projects;
        projects = new ControlPanelMain().getProjectsByCalendar(id);

        DefaultListModel model = new DefaultListModel();
        //model.addElement("****Personal");
        for (ProjectVO project : projects) {
            if (project.getType() == 0) {
                model.addElement(project);
            }
        }
        //model.addElement("****Trabajo");
        for (ProjectVO project : projects) {
            if (project.getType() == 1) {
                model.addElement(project);
            }
        }
        //model.addElement("****Educacion");
        for (ProjectVO project : projects) {
            if (project.getType() == 2) {
                model.addElement(project);
            }
        }
        jComboBoxTaskProject.removeAllItems();
        for (ProjectVO project : projects) {
            jComboBoxTaskProject.addItem(project);
        }

        if (!projects.isEmpty()) {
            jListProjects = new JList(model);
            jScrollPaneProjects.getViewport().removeAll();
            jScrollPaneProjects.getViewport().add(jListProjects);
            jScrollPaneProjects.getViewport().setVisible(true);
            jListProjects.addListSelectionListener(new javax.swing.event.ListSelectionListener() {

                @Override
                public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                    jListProjectsValueChanged(evt);
                }
            });
        }
    }

    private void loadOverdueTasks() {
        StudentVO alumno = new ControlPanelMyAccount().findByIp();
        int id = alumno.getCalendarId();
        List<TaskVO> tasks;
        tasks = new ControlPanelMain().getTasksByCalendar(id);
        Collections.sort(tasks, new Comparator() {

            @Override
            public int compare(Object o1, Object o2) {
                TaskVO p1 = (TaskVO) o1;
                TaskVO p2 = (TaskVO) o2;
                return p1.getStartDate().compareTo(p2.getStartDate());
            }
        });

        if (!tasks.isEmpty()) {
            ArrayList<Date> dates = new ArrayList<>();
            for (TaskVO task : tasks) {
                if (!task.getCurrentState().equals("Completado")) {
                    if (!dates.contains(task.getStartDate())) {
                        dates.add(task.getStartDate());
                    }
                }
            }
            jPanelPending.setVisible(false);
            jPanelPending.removeAll();
            SimpleDateFormat format = new SimpleDateFormat("MMMMM dd");
            GroupLayout layoutPanelPending = (GroupLayout) jPanelPending.getLayout();
            GroupLayout.SequentialGroup leftRight = layoutPanelPending.createSequentialGroup();
            GroupLayout.SequentialGroup topBottom = layoutPanelPending.createSequentialGroup();
            GroupLayout.ParallelGroup firstColumn = layoutPanelPending.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING);

            Collections.sort(tasks, new Comparator() {

                @Override
                public int compare(Object o1, Object o2) {
                    TaskVO p1 = (TaskVO) o1;
                    TaskVO p2 = (TaskVO) o2;
                    return new Integer(p1.getPriority()).compareTo(p2.getPriority());
                }
            });

            for (Date date : dates) {

                JPanel panel = new JPanel();
                panel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, format.format(date), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 0, 14), new java.awt.Color(204, 0, 204))); // NOI18N
                GroupLayout layout = new GroupLayout(panel);
                GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup();
                GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup();
                GroupLayout.ParallelGroup column1 = layout.createParallelGroup();
                GroupLayout.ParallelGroup column2 = layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING);
                panel.setLayout(layout);

                for (TaskVO task : tasks) {
                    if (task.getStartDate().equals(date)) {

                        GroupLayout.ParallelGroup row = layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER);


                        JButton buttonDetails = new JButton("Ver Detalles");
                        buttonDetails.setName(new Integer(task.getId()).toString());
                        JLabel label = new JLabel(task.getName());

                        buttonDetails.setVisible(true);

                        buttonDetails.addActionListener(new java.awt.event.ActionListener() {

                            @Override
                            public void actionPerformed(java.awt.event.ActionEvent evt) {
                                detailsButtonActionPerformed(evt);
                            }
                        });
                        if (!task.getCurrentState().equals("Completado")) {
                            colorLabel(task, label);
                        } else {
                            label.setForeground(Color.lightGray);
                        }

                        column1.addComponent(label);
                        column2.addComponent(buttonDetails);
                        row.addComponent(label);
                        row.addComponent(buttonDetails);
                        topToBottom.addGroup(row);
                    }
                }
                leftToRight.addGroup(column1);
                leftToRight.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
                leftToRight.addGroup(column2);
                layout.setHorizontalGroup(leftToRight);
                layout.setVerticalGroup(topToBottom);
                topBottom.addComponent(panel);
                firstColumn.addComponent(panel);
            }
            leftRight.addGroup(firstColumn);
            layoutPanelPending.setHorizontalGroup(leftRight);
            layoutPanelPending.setVerticalGroup(topBottom);
            for (java.awt.Component c : jPanelPending.getComponents()) {
                c.setMinimumSize(new Dimension(jPanelPending.getMinimumSize().width - 30, c.getHeight()));
                c.setVisible(true);
            }
            jPanelPending.setVisible(true);
        }
    }

    private void loadDaysWithTasks() {
        //TODO throw new UnsupportedOperationException("Not yet implemented");
    }

    private void loadTasksDay() {
        List<TaskVO> tasks = new ControlPanelMain().getTaskByDate(jCalendarPrincipalPane.getDate());
        Collections.sort(tasks, new Comparator() {

            @Override
            public int compare(Object o1, Object o2) {
                TaskVO p1 = (TaskVO) o1;
                TaskVO p2 = (TaskVO) o2;
                return new Integer(p1.getProjectId()).compareTo(p2.getProjectId());
            }
        });
        //if (!tasks.isEmpty()) {
        ArrayList<Integer> projectIds = new ArrayList<>();
        for (TaskVO task : tasks) {
            if (!projectIds.contains(task.getProjectId())) {
                projectIds.add(task.getProjectId());
            }
        }
        jPanelTask.setVisible(false);
        jPanelTask.removeAll();
        SimpleDateFormat format = new SimpleDateFormat("MMMMM dd");
        String title;
        if (format.format(jCalendarPrincipalPane.getDate()).equals(format.format(new GregorianCalendar().getTime()))) {
            title = "Hoy";
        } else {
            title = format.format(jCalendarPrincipalPane.getDate());
        }
        jPanelTask.setBorder(javax.swing.BorderFactory.createTitledBorder(null, title, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 0, 14), new java.awt.Color(0, 0, 255)));
        GroupLayout layoutPanelPending = (GroupLayout) jPanelTask.getLayout();
        GroupLayout.SequentialGroup leftRight = layoutPanelPending.createSequentialGroup();
        GroupLayout.SequentialGroup topBottom = layoutPanelPending.createSequentialGroup();
        GroupLayout.ParallelGroup firstColumn = layoutPanelPending.createParallelGroup();

        Collections.sort(tasks, new Comparator() {

            @Override
            public int compare(Object o1, Object o2) {
                TaskVO p1 = (TaskVO) o1;
                TaskVO p2 = (TaskVO) o2;
                return new Integer(p1.getPriority()).compareTo(p2.getPriority());
            }
        });

        for (Integer projectId : projectIds) {

            JPanel panel = new JPanel();
            panel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, new ControlPanelMain().findProject(projectId).getName(), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 0, 14), new java.awt.Color(204, 0, 204))); // NOI18N
            GroupLayout layout = new GroupLayout(panel);
            GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup();
            GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup();
            GroupLayout.ParallelGroup column1 = layout.createParallelGroup();
            GroupLayout.ParallelGroup column2 = layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING);
            panel.setLayout(layout);

            for (TaskVO task : tasks) {
                if (task.getProjectId() == projectId) {

                    GroupLayout.ParallelGroup row = layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER);


                    JButton buttonDetails = new JButton("Ver Detalles");
                    buttonDetails.setName(new Integer(task.getId()).toString());
                    JLabel label = new JLabel(task.getName());

                    buttonDetails.setVisible(true);

                    buttonDetails.addActionListener(new java.awt.event.ActionListener() {

                        @Override
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                            detailsButtonActionPerformed(evt);
                        }
                    });
                    if (!task.getCurrentState().equals("Completado")) {
                        colorLabel(task, label);
                    } else {
                        label.setForeground(Color.lightGray);
                    }

                    column1.addComponent(label);
                    column2.addComponent(buttonDetails);
                    row.addComponent(label);
                    row.addComponent(buttonDetails);
                    topToBottom.addGroup(row);
                }
            }
            leftToRight.addGroup(column1);
            leftToRight.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
            leftToRight.addGroup(column2);
            layout.setHorizontalGroup(leftToRight);
            layout.setVerticalGroup(topToBottom);
            topBottom.addComponent(panel);
            firstColumn.addComponent(panel);
        }
        leftRight.addGroup(firstColumn);
        layoutPanelPending.setHorizontalGroup(leftRight);
        layoutPanelPending.setVerticalGroup(topBottom);
        for (java.awt.Component c : jPanelTask.getComponents()) {
            c.setMinimumSize(new Dimension(jPanelTask.getMinimumSize().width - 30, c.getHeight()));
            c.setVisible(true);
        }
        jPanelTask.setVisible(true);
        //}
    }

    private void fillTaskPanel(Integer taskId) {
        TaskVO task = new ControlPanelMain().findTask(taskId);
        jTextFieldTaskName.setText(task.getName());
        jDateChooserInitialTasksDate.setDate(task.getStartDate());
        jDateChooserEndTaskDate.setDate(task.getDeadlineDate());
        jSpinnerPriority.setValue(task.getPriority());
        jTextAreaTasks.setText(task.getDetails());
        jComboBoxState.setSelectedItem(task.getCurrentState());
        jComboBoxTaskProject.setSelectedItem(new ControlPanelMain().findProject(task.getProjectId()));
        jButtonModifyTask.setEnabled(true);
        jButtonRemoveTask.setEnabled(true);
//        jButtonCreateTask.setEnabled(false);
        jButtonCreateTask.setText("Limpiar");
        jButtonCreateTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Wizard.png")));
        jLabelIdTask.setText(new Integer(task.getId()).toString());
    }

    @Override
    public void update() {
        loadProjects();
        loadOverdueTasks();
        loadDaysWithTasks();
        loadTasksDay();
        //this.repaint();
    }

    public synchronized static MainPanel getInstance() {
        if (instance == null) {
            instance = new MainPanel();
        }

        return instance;
    }
    private static MainPanel instance;

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jToolBarSearchProject = new javax.swing.JToolBar();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldSearchProject = new javax.swing.JTextField();
        jSplitPane4 = new javax.swing.JSplitPane();
        jCalendarPrincipalPane = new com.toedter.calendar.JCalendar();
        jPanelProjectsTree = new javax.swing.JPanel();
        jButtonAddProject = new javax.swing.JButton();
        jButtonRemoveProject = new javax.swing.JButton();
        jScrollPaneProjects = new javax.swing.JScrollPane();
        jListProjects = new javax.swing.JList();
        jSplitPane2 = new javax.swing.JSplitPane();
        jPanelTasksPr = new javax.swing.JPanel();
        jSplitPane3 = new javax.swing.JSplitPane();
        jPanelTasksOptionsPr = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButtonCreateTask = new javax.swing.JButton();
        jButtonModifyTask = new javax.swing.JButton();
        jButtonRemoveTask = new javax.swing.JButton();
        jTextFieldTaskName = new javax.swing.JTextField();
        jDateChooserInitialTasksDate = new com.toedter.calendar.JDateChooser();
        jComboBoxTaskProject = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jDateChooserEndTaskDate = new com.toedter.calendar.JDateChooser();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextAreaTasks = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxState = new javax.swing.JComboBox();
        jSpinnerPriority = new javax.swing.JSpinner();
        jLabel8 = new javax.swing.JLabel();
        jLabelIdTask = new javax.swing.JLabel();
        jScrollPaneTask = new javax.swing.JScrollPane();
        jPanelTask = new javax.swing.JPanel();
        jScrollPanePending = new javax.swing.JScrollPane();
        jPanelPending = new javax.swing.JPanel();

        jToolBarSearchProject.setRollover(true);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Search.png"))); // NOI18N
        jToolBarSearchProject.add(jLabel5);

        jTextFieldSearchProject.setForeground(new java.awt.Color(102, 102, 102));
        jTextFieldSearchProject.setText("Buscar proyecto");
        jTextFieldSearchProject.setPreferredSize(new java.awt.Dimension(125, 32));
        jTextFieldSearchProject.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldSearchProjectKeyPressed(evt);
            }
        });
        jToolBarSearchProject.add(jTextFieldSearchProject);

        jSplitPane4.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jCalendarPrincipalPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Calendario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(0, 153, 153))); // NOI18N
        jCalendarPrincipalPane.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        jCalendarPrincipalPane.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jCalendarPrincipalPanePropertyChange(evt);
            }
        });
        jSplitPane4.setLeftComponent(jCalendarPrincipalPane);

        jPanelProjectsTree.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Proyectos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14))); // NOI18N

        jButtonAddProject.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Plus.png"))); // NOI18N
        jButtonAddProject.setText("Añadir");
        jButtonAddProject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddProjectActionPerformed(evt);
            }
        });

        jButtonRemoveProject.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Minus.png"))); // NOI18N
        jButtonRemoveProject.setText("Eliminar");
        jButtonRemoveProject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRemoveProjectActionPerformed(evt);
            }
        });

        jListProjects.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListProjectsValueChanged(evt);
            }
        });
        jListProjects.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jListProjectsFocusLost(evt);
            }
        });
        jScrollPaneProjects.setViewportView(jListProjects);

        javax.swing.GroupLayout jPanelProjectsTreeLayout = new javax.swing.GroupLayout(jPanelProjectsTree);
        jPanelProjectsTree.setLayout(jPanelProjectsTreeLayout);
        jPanelProjectsTreeLayout.setHorizontalGroup(
            jPanelProjectsTreeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelProjectsTreeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelProjectsTreeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelProjectsTreeLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButtonAddProject)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonRemoveProject))
                    .addComponent(jScrollPaneProjects, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelProjectsTreeLayout.setVerticalGroup(
            jPanelProjectsTreeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelProjectsTreeLayout.createSequentialGroup()
                .addComponent(jScrollPaneProjects, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelProjectsTreeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonRemoveProject)
                    .addComponent(jButtonAddProject))
                .addContainerGap())
        );

        jSplitPane4.setRightComponent(jPanelProjectsTree);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBarSearchProject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(12, 12, Short.MAX_VALUE)
                .addComponent(jSplitPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jToolBarSearchProject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
                .addContainerGap())
        );

        jSplitPane1.setLeftComponent(jPanel1);

        jPanelTasksPr.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tareas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(0, 51, 51))); // NOI18N

        jSplitPane3.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jPanelTasksOptionsPr.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opciones de Tareas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(0, 51, 51))); // NOI18N

        jLabel1.setFont(jLabel1.getFont());
        jLabel1.setText("Nombre");

        jLabel2.setFont(jLabel2.getFont());
        jLabel2.setText("Fecha de Inicio");

        jLabel4.setFont(jLabel4.getFont());
        jLabel4.setText("Proyecto");

        jButtonCreateTask.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        jButtonCreateTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Plus.png"))); // NOI18N
        jButtonCreateTask.setText("Crear");
        jButtonCreateTask.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreateTaskActionPerformed(evt);
            }
        });

        jButtonModifyTask.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        jButtonModifyTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Write3.png"))); // NOI18N
        jButtonModifyTask.setText("Modificar");
        jButtonModifyTask.setEnabled(false);
        jButtonModifyTask.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonModifyTaskActionPerformed(evt);
            }
        });

        jButtonRemoveTask.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        jButtonRemoveTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Minus.png"))); // NOI18N
        jButtonRemoveTask.setText("Remover");
        jButtonRemoveTask.setEnabled(false);
        jButtonRemoveTask.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRemoveTaskActionPerformed(evt);
            }
        });

        jTextFieldTaskName.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        jTextFieldTaskName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldTaskNameActionPerformed(evt);
            }
        });

        jDateChooserInitialTasksDate.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        jDateChooserInitialTasksDate.setMinSelectableDate(new GregorianCalendar().getTime());

        jComboBoxTaskProject.setFont(jComboBoxTaskProject.getFont());

        jLabel6.setFont(jLabel6.getFont());
        jLabel6.setText("Fecha de Entrega");

        jDateChooserEndTaskDate.setFont(new java.awt.Font("Segoe UI Light", 0, 12)); // NOI18N
        jDateChooserEndTaskDate.setMinSelectableDate(new GregorianCalendar().getTime());

        jLabel7.setFont(jLabel7.getFont());
        jLabel7.setText("Prioridad");

        jTextAreaTasks.setColumns(20);
        jTextAreaTasks.setRows(5);
        jScrollPane4.setViewportView(jTextAreaTasks);

        jLabel3.setText("Estado");

        jComboBoxState.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Completado", "Delegado/Pendiente" }));

        jLabel8.setText("Detalles:");

        jLabelIdTask.setEnabled(false);

        javax.swing.GroupLayout jPanelTasksOptionsPrLayout = new javax.swing.GroupLayout(jPanelTasksOptionsPr);
        jPanelTasksOptionsPr.setLayout(jPanelTasksOptionsPrLayout);
        jPanelTasksOptionsPrLayout.setHorizontalGroup(
            jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTasksOptionsPrLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanelTasksOptionsPrLayout.createSequentialGroup()
                            .addComponent(jButtonCreateTask)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButtonModifyTask)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButtonRemoveTask))
                        .addGroup(jPanelTasksOptionsPrLayout.createSequentialGroup()
                            .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1)
                                .addComponent(jLabel2)
                                .addComponent(jLabel6)
                                .addComponent(jLabel4)
                                .addComponent(jLabel3)
                                .addComponent(jLabel7)
                                .addComponent(jLabel8))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jComboBoxState, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jSpinnerPriority, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jComboBoxTaskProject, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jDateChooserEndTaskDate, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jDateChooserInitialTasksDate, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextFieldTaskName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(33, 33, 33)))
                    .addComponent(jLabelIdTask))
                .addContainerGap(16, Short.MAX_VALUE))
        );
        jPanelTasksOptionsPrLayout.setVerticalGroup(
            jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTasksOptionsPrLayout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldTaskName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jDateChooserInitialTasksDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3)
                .addComponent(jLabelIdTask)
                .addGap(1, 1, 1)
                .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jDateChooserEndTaskDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBoxTaskProject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jSpinnerPriority, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(1, 1, 1)
                .addComponent(jLabel8)
                .addGap(2, 2, 2)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelTasksOptionsPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCreateTask)
                    .addComponent(jButtonModifyTask)
                    .addComponent(jButtonRemoveTask))
                .addContainerGap(44, Short.MAX_VALUE))
        );

        jSplitPane3.setRightComponent(jPanelTasksOptionsPr);

        jScrollPaneTask.setMinimumSize(new java.awt.Dimension(375, 150));

        jPanelTask.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Hoy", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 255)));
        jPanelTask.setMinimumSize(new java.awt.Dimension(375, 150));

        javax.swing.GroupLayout jPanelTaskLayout = new javax.swing.GroupLayout(jPanelTask);
        jPanelTask.setLayout(jPanelTaskLayout);
        jPanelTaskLayout.setHorizontalGroup(
            jPanelTaskLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 363, Short.MAX_VALUE)
        );
        jPanelTaskLayout.setVerticalGroup(
            jPanelTaskLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 244, Short.MAX_VALUE)
        );

        jScrollPaneTask.setViewportView(jPanelTask);

        jSplitPane3.setTopComponent(jScrollPaneTask);

        javax.swing.GroupLayout jPanelTasksPrLayout = new javax.swing.GroupLayout(jPanelTasksPr);
        jPanelTasksPr.setLayout(jPanelTasksPrLayout);
        jPanelTasksPrLayout.setHorizontalGroup(
            jPanelTasksPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTasksPrLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 375, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelTasksPrLayout.setVerticalGroup(
            jPanelTasksPrLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTasksPrLayout.createSequentialGroup()
                .addComponent(jSplitPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 553, Short.MAX_VALUE)
                .addContainerGap())
        );

        jSplitPane2.setLeftComponent(jPanelTasksPr);

        jPanelPending.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pendiente...", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(204, 0, 0))); // NOI18N
        jPanelPending.setMinimumSize(new java.awt.Dimension(296, 593));

        javax.swing.GroupLayout jPanelPendingLayout = new javax.swing.GroupLayout(jPanelPending);
        jPanelPending.setLayout(jPanelPendingLayout);
        jPanelPendingLayout.setHorizontalGroup(
            jPanelPendingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 284, Short.MAX_VALUE)
        );
        jPanelPendingLayout.setVerticalGroup(
            jPanelPendingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 564, Short.MAX_VALUE)
        );

        jScrollPanePending.setViewportView(jPanelPending);

        jSplitPane2.setRightComponent(jScrollPanePending);

        jSplitPane1.setRightComponent(jSplitPane2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1078, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonAddProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddProjectActionPerformed
        AuxiliarFrame aux = new AuxiliarFrame();
        aux.cambiarPanel(new PanelAddProject(aux));
        aux.setVisible(true);
    }//GEN-LAST:event_jButtonAddProjectActionPerformed

    private void jButtonRemoveProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoveProjectActionPerformed
        // TODO add your handling code here:
        ProjectVO project = (ProjectVO) jListProjects.getSelectedValue();
        int confirm = JOptionPane.showConfirmDialog(this, "Al eliminar el proyecto se eliminarán las tareas asociadas al mismo\n Desea continuar?", "Aviso", JOptionPane.YES_NO_OPTION);
        if (confirm == JOptionPane.YES_OPTION) {
            if (new ControlPanelMain().deleteProject(project.getId())) {
                JOptionPane.showMessageDialog(this, "Proyecto eliminado correctamente", "Aviso", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "El proyecto no se ha podido eliminar", "Aviso", JOptionPane.ERROR_MESSAGE);
            }
        }
        update();
    }//GEN-LAST:event_jButtonRemoveProjectActionPerformed

    private void jButtonCreateTaskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCreateTaskActionPerformed
        switch (jButtonCreateTask.getText()) {
            case "Crear":
                TaskVO task = new TaskVO();
                task.setName(jTextFieldTaskName.getText());
                task.setStartDate(jDateChooserInitialTasksDate.getDate());
                task.setDeadlineDate(jDateChooserEndTaskDate.getDate());
                task.setPriority((int) jSpinnerPriority.getValue());
                task.setProjectId(((ProjectVO) jComboBoxTaskProject.getSelectedItem()).getId());
                task.setCurrentState(jComboBoxState.getSelectedItem().toString());
                task.setDetails(jTextAreaTasks.getText());
                if (new ControlPanelMain().createTask(task)) {
                    update();
                    resetFieldsTask();
                    JOptionPane.showMessageDialog(this, "Tarea creada correctamente", "Aviso", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(this, "Se deben llenar los campos de Nombre, Fechas y Seleccionar un proyecto", "Aviso", JOptionPane.INFORMATION_MESSAGE);
                }
                break;
            case "Limpiar":
                resetFieldsTask();
                break;
        }
    }//GEN-LAST:event_jButtonCreateTaskActionPerformed

    private void jButtonModifyTaskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyTaskActionPerformed
        TaskVO task = new TaskVO();
        task.setId(new Integer(jLabelIdTask.getText()));
        task.setName(jTextFieldTaskName.getText());
        task.setStartDate(jDateChooserInitialTasksDate.getDate());
        task.setDeadlineDate(jDateChooserEndTaskDate.getDate());
        task.setPriority((int) jSpinnerPriority.getValue());
        task.setProjectId(((ProjectVO) jComboBoxTaskProject.getSelectedItem()).getId());
        task.setCurrentState(jComboBoxState.getSelectedItem().toString());
        task.setDetails(jTextAreaTasks.getText());
        if (new ControlPanelMain().updateTask(task)) {
            update();
            resetFieldsTask();
            JOptionPane.showMessageDialog(this, "Tarea modificada correctamente", "Aviso", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "Se deben llenar los campos de Nombre, Fechas y Seleccionar un proyecto", "Aviso", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jButtonModifyTaskActionPerformed

    private void jButtonRemoveTaskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoveTaskActionPerformed
        if (new ControlPanelMain().deleteTask(new Integer(jLabelIdTask.getText()))) {
            update();
            resetFieldsTask();
            JOptionPane.showMessageDialog(this, "Tarea eliminada correctamente", "Aviso", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "No se ha podido eliminar la Tarea", "Aviso", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jButtonRemoveTaskActionPerformed

    private void jTextFieldTaskNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldTaskNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldTaskNameActionPerformed

    private void jTextFieldSearchProjectKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldSearchProjectKeyPressed
        // TODO add your handling code here:
        jTextFieldSearchProject.setText(" ");
    }//GEN-LAST:event_jTextFieldSearchProjectKeyPressed

    private void jListProjectsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListProjectsValueChanged
        ProjectVO project = (ProjectVO) jListProjects.getSelectedValue();
        Collections.sort(project.getTasks(), new Comparator() {

            @Override
            public int compare(Object o1, Object o2) {
                TaskVO p1 = (TaskVO) o1;
                TaskVO p2 = (TaskVO) o2;
                return p1.getStartDate().compareTo(p2.getStartDate());
            }
        });

        ArrayList<Date> dates = new ArrayList<>();
        for (TaskVO task : project.getTasks()) {
            if (!dates.contains(task.getStartDate())) {
                dates.add(task.getStartDate());
            }
        }
        jPanelTask.setVisible(false);
        jPanelTask.removeAll();
        SimpleDateFormat format = new SimpleDateFormat("MMMMM dd");
        jPanelTask.setBorder(javax.swing.BorderFactory.createTitledBorder(null, project.getName(), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 0, 14), new java.awt.Color(0, 0, 255)));
        GroupLayout layoutPanelPending = (GroupLayout) jPanelTask.getLayout();
        GroupLayout.SequentialGroup leftRight = layoutPanelPending.createSequentialGroup();
        GroupLayout.SequentialGroup topBottom = layoutPanelPending.createSequentialGroup();
        GroupLayout.ParallelGroup firstColumn = layoutPanelPending.createParallelGroup();

        Collections.sort(project.getTasks(), new Comparator() {

            @Override
            public int compare(Object o1, Object o2) {
                TaskVO p1 = (TaskVO) o1;
                TaskVO p2 = (TaskVO) o2;
                return new Integer(p1.getPriority()).compareTo(p2.getPriority());
            }
        });

        for (Date date : dates) {

            JPanel panel = new JPanel();
            panel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, format.format(date), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 0, 14), new java.awt.Color(204, 0, 204))); // NOI18N
            GroupLayout layout = new GroupLayout(panel);
            GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup();
            GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup();
            GroupLayout.ParallelGroup column1 = layout.createParallelGroup();
            GroupLayout.ParallelGroup column2 = layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING);
            panel.setLayout(layout);

            for (TaskVO task : project.getTasks()) {
                if (task.getStartDate().equals(date)) {

                    GroupLayout.ParallelGroup row = layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER);


                    JButton buttonDetails = new JButton("Ver Detalles");
                    buttonDetails.setName(new Integer(task.getId()).toString());
                    JLabel label = new JLabel(task.getName());

                    buttonDetails.setVisible(true);

                    buttonDetails.addActionListener(new java.awt.event.ActionListener() {

                        @Override
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                            detailsButtonActionPerformed(evt);
                        }
                    });
                    colorLabel(task, label);

                    column1.addComponent(label);
                    column2.addComponent(buttonDetails);
                    row.addComponent(label);
                    row.addComponent(buttonDetails);
                    topToBottom.addGroup(row);
                }
            }
            leftToRight.addGroup(column1);
            leftToRight.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
            leftToRight.addGroup(column2);
            layout.setHorizontalGroup(leftToRight);
            layout.setVerticalGroup(topToBottom);
            topBottom.addComponent(panel);
            firstColumn.addComponent(panel);
        }
        leftRight.addGroup(firstColumn);
        layoutPanelPending.setHorizontalGroup(leftRight);
        layoutPanelPending.setVerticalGroup(topBottom);
        for (java.awt.Component c : jPanelTask.getComponents()) {
            c.setMinimumSize(new Dimension(jPanelTask.getMinimumSize().width - 30, c.getHeight()));
            c.setVisible(true);
        }
        jPanelTask.setVisible(true);
        resetFieldsTask();

    }//GEN-LAST:event_jListProjectsValueChanged

    private void jCalendarPrincipalPanePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jCalendarPrincipalPanePropertyChange
        loadTasksDay();
        resetFieldsTask();
    }//GEN-LAST:event_jCalendarPrincipalPanePropertyChange

    private void jListProjectsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jListProjectsFocusLost
        jListProjects.setSelectedIndex(0);
    }//GEN-LAST:event_jListProjectsFocusLost
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAddProject;
    private javax.swing.JButton jButtonCreateTask;
    private javax.swing.JButton jButtonModifyTask;
    private javax.swing.JButton jButtonRemoveProject;
    private javax.swing.JButton jButtonRemoveTask;
    private com.toedter.calendar.JCalendar jCalendarPrincipalPane;
    private javax.swing.JComboBox jComboBoxState;
    private javax.swing.JComboBox jComboBoxTaskProject;
    private com.toedter.calendar.JDateChooser jDateChooserEndTaskDate;
    private com.toedter.calendar.JDateChooser jDateChooserInitialTasksDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelIdTask;
    private javax.swing.JList jListProjects;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelPending;
    private javax.swing.JPanel jPanelProjectsTree;
    private javax.swing.JPanel jPanelTask;
    private javax.swing.JPanel jPanelTasksOptionsPr;
    private javax.swing.JPanel jPanelTasksPr;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPanePending;
    private javax.swing.JScrollPane jScrollPaneProjects;
    private javax.swing.JScrollPane jScrollPaneTask;
    private javax.swing.JSpinner jSpinnerPriority;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JSplitPane jSplitPane3;
    private javax.swing.JSplitPane jSplitPane4;
    private javax.swing.JTextArea jTextAreaTasks;
    private javax.swing.JTextField jTextFieldSearchProject;
    private javax.swing.JTextField jTextFieldTaskName;
    private javax.swing.JToolBar jToolBarSearchProject;
    // End of variables declaration//GEN-END:variables

    private void resetFieldsTask() {
        jTextFieldTaskName.setText("");
        jDateChooserInitialTasksDate.setDate(null);
        jDateChooserEndTaskDate.setDate(null);
        jSpinnerPriority.setValue(0);
        jTextAreaTasks.setText("");
        jButtonModifyTask.setEnabled(false);
        jButtonRemoveTask.setEnabled(false);
        jButtonCreateTask.setEnabled(true);
        jButtonCreateTask.setText("Crear");
        jButtonCreateTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/presentation/view/images/Plus.png")));
    }

    private void detailsButtonActionPerformed(java.awt.event.ActionEvent evt) {
        JButton button = (JButton) evt.getSource();

        fillTaskPanel(new Integer(button.getName()));

    }

    private void colorLabel(TaskVO task, JLabel label) {
        switch (task.getPriority()) {
            case 1:
                label.setForeground(Color.red);
                break;
            case 2:
                label.setForeground(Color.orange);
                break;
            case 3:
                label.setForeground(Color.yellow);
                break;
            case 4:
                label.setForeground(Color.green);
                break;
            case 5:
                label.setForeground(Color.blue);
                break;
            default:
                break;
        }
    }
}
